package com.chemical.search.filter;

import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;

/**
 *@className:CustomHibernateSessionFilter.java
 *@classDescription:
 *@author:MChen
 *@createTime:2012-4-19
 */
public class CustomHibernateSessionFilter extends OpenSessionInViewFilter {

    /**
     * 覆盖父类的获取Session操作
     */
    protected Session getSession(SessionFactory sessionFactory)
                        throws DataAccessResourceFailureException {
        Session session = super.getSession(sessionFactory);
        //设置成动态
        session.setFlushMode(FlushMode.AUTO);   
        return session;
    }
    /**
     * 关闭Session
     */
	protected void closeSession(Session session, SessionFactory sessionFactory){
        session.flush(); 
        super.closeSession(session, sessionFactory); 
    }
}
